package com.pshcp.service;

import com.framework.util.DateUtil;
import com.framework.util.SystemUtil;
import com.pshcp.common.enums.CommonStatusEnum;
import com.pshcp.domain.model.Session;
import com.pshcp.mapper.SessionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @Description: TODO
 * @Author: xiaoche
 * @Date: 2022/11/3 10:00
 */
@Service
public class SessionService {

    @Autowired
    private SessionMapper sessionMapper;

    public int insert(Session session) {
        session.setStatus(CommonStatusEnum.INIT.getCode());
        session.setCreatedTime(new Date());
        return sessionMapper.insert(session);
    }

    public int update(Session session) {
        session.setUpdateTime(new Date());
        return sessionMapper.updateByPrimaryKeySelective(session);
    }

    public Session findById(Long id) {
        return sessionMapper.selectByPrimaryKey(id);
    }

    public void stopUseSession(Long id){
        if (id == null) {
            return;
        }
        Session session = findById(id);
        session.setBizStatus(1);
        session.setUpdateTime(DateUtil.currDate());
        sessionMapper.updateByPrimaryKey(session);
    }
}
